<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title> 处理各种表单</title>

</head>

<body>
    <form methoct="post" action=""  onsubmit=" return eg.regCheck();">
             <input type="hidden" name="" id="errnum" value="0"> 
         账号 :<input type="text" name="" id="userid" /><br /><br />  
         密码;<input type="password" name="" id="userpwd" /><br /><br />  
         确认:<input type="password" name="" id="userpwd2" /><br /><br /> 
         简介：<textarea name="" rows="4" cols="l8" id="about"></textarea> <br /><br /> 
         <input type="submit" value="注册" id="regBtn" />
         <input type="button" value="解锁" onclick="eg.unlock()" style="display:none;" id="regunlock" /> 
    </form>
    <script> var eg={};
    eg.$=function(id){
        return document.getElementById(id);
    }
    eg.regCheck=function(){
        var uid=eg.$("userid");
        var upwd=eg.$("userpwd");
        var upwd2=eg.$("userpwd2");
        if(uid.value==""){
            alert("账号不能为空");
            eg.err();
            return false;
        }
        if(upwd.value==""){
            alert("密码不能为空");
            eg.err();
            return false;
        }
        if(upwd!=upwd2){
            alert("两次密码不一致");
            eg.err();
            return false;
        }
        var about=eg.$("about");
        if(about.value.length>50){
            alert("简介不能超过50个字符");
            eg.err();
            return false;
        }
        return true;

    };
    eg.err=function(){
        var el=eg.$("errnum");
        var old=el.value;
        el.value=parseInt(old)+1;
        eg.lock();
        
    };
    eg.lock=function(){
        var err=eg.$("errnum");
        if(parseInt(err.value)>=3){
            eg.$("regBtn").disabled=true;
            eg.$("regunlock").style.disabled="block"
        }
    };
    eg.unlock=function(){
        eg.$("regBtn").disabled=false;
        eg.$("regunlock").style.display="none";
        eg.$("errnum").value=0;
    };
    
    </script > 
</body>
</HTML>